import { defineStore } from "pinia";
import {defaultSettings} from '@/setting.ts'
const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || ''

export const useTagViewStore = defineStore("tagView", {
  state: () => {
    return {
      theme:storageSetting.theme || '#409EFF',
      visitedViews: [],
      cachedViews: [],
    };
  },
  actions: {
    addView(view: any) {
      this.addVisitedView(view);
    },
    addVisitedView(view: any) {
      if (this.visitedViews.some((v: any) => v.path === view.path)) return;
      if (view.meta) {
        this.visitedViews.push(
          Object.assign({},view,{
            title: view.meta.title || 'no-name',
          })
        );
      }
    },
    delView(view: any) {
      console.log("🚀 ~ delView ~ view:", view)
      
      this.visitedViews = this.visitedViews.filter((v: any) => {
        return v.path !== view.path;
      });
    }
  },
});
